package in.ac.iiitd.cse201.Devansh2011042.finallabexam;

/**
 * The class that encapsulates a slot in the buffer pool that holds a page (the
 * payload) and also additional metadata required for the correct buffer
 * management such as reference counts, pin/unpin flag, etc.
 *
 * @author bedathur
 */
public class BufferSlot<P> {

    private final int key;
    public int refCount;
    public boolean isPinned;
    private final P payload;

    /**
     * Constructor of a BufferSlot that takes the key of the payload and the
     * payload itself.
     *
     * @param k
     * @param t
     */
    public BufferSlot(int k, P t) {
        key = k;
        payload = t;

        isPinned = false;
        refCount = 0;
    }

    /**
     * Return the reference to the payload contained in the BufferSlot. Note
     * that the calling program can only modify the contents of the payload but
     * not replace the payload.
     *
     */
    public P getPayload() {
        return payload;
    }

    /**
     * Return the key of the BufferSlot.
     */
    public int getKey() {
        return key;
    }
    
    public boolean equals(BufferSlot <P> o) {
        if (this.key == o.key)
            return true;
        return false;
    }
    
}
